package com.os.opencv.java.chapter7;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

public class MorphologyEx2 {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        //读取图像并在屏幕上显示
        Mat src = Imgcodecs.imread("/Users/matt/Pictures/111.jpg", Imgcodecs.IMREAD_GRAYSCALE);
        HighGui.imshow("src", src);
        HighGui.waitKey(0);
        Mat dst = new Mat();

        //转换为二值图并在屏幕上显示
        Imgproc.threshold(src, src, 120, 255, Imgproc.THRESH_BINARY);
        HighGui.imshow("binary", src);
        HighGui.waitKey(0);

        //顶帽运算3次并在屏幕上显示
        Point anchor = new Point(-1, -1);
        Imgproc.morphologyEx(src, dst, Imgproc.MORPH_TOPHAT, new Mat(), anchor, 3);
        HighGui.imshow("tophat", dst);
        HighGui.waitKey(0);

        //黑帽运算3次并在屏幕上显示
        Imgproc.morphologyEx(src, dst, Imgproc.MORPH_BLACKHAT, new Mat(), anchor, 3);
        HighGui.imshow("blackhat", dst);
        HighGui.waitKey(0);

        System.exit(0);

    }
}
